from qiyeweixin_testing.until.log_utils import logger


def click_exprction(by, element, max_attempts=5):
    def __inner(driver):
        actul_attempts = 0

        while actul_attempts < max_attempts:
            actul_attempts += 1

            try:
                driver.find_element(by, element).click()
                return True
            except Exception:
                logger.debug(f"点击{actul_attempts}次")

        raise Exception(f'超出了最大点击次数{max_attempts}')

    return __inner